package com.shiguiwu.facade.starter.door.config;

import com.shiguiwu.facade.starter.door.aspect.DoorAspect;
import com.shiguiwu.facade.starter.door.service.FacadeService;
import com.shiguiwu.facade.starter.door.prop.FacadeProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: 自动配置类
 * @author: stone
 * @date: Created by 2021/8/29 11:43
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.facade.starter.door.config
 */
@Configuration
@ConditionalOnClass(FacadeService.class)
@EnableConfigurationProperties(FacadeProperties.class)
public class FacadeAutoConfiguration {


    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "com.shiguiwu.facade",value = "enable",havingValue = "true")
    public FacadeService facadeService(FacadeProperties facadeProperties) {
        return new FacadeService(facadeProperties.getUserString());
    }


    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "com.shiguiwu.facade",value = "enable",havingValue = "true")
    public DoorAspect doorAspect(FacadeService facadeService) {
        return new DoorAspect(facadeService);
    }




}
